package co.edu.usbcali.raju.games.chess;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

import jpl.Query;

import co.edu.usbcali.raju.games.chess.controller.ChessController;
import co.edu.usbcali.raju.games.chess.gui.ChessGui;
import co.edu.usbcali.raju.games.chess.helpers.ChessBoardFactory;
import co.edu.usbcali.raju.games.chess.model.ChessBoard;
import co.edu.usbcali.raju.games.chess.model.ChessCell;
import co.edu.usbcali.raju.games.chess.model.ChessPiece;
import co.edu.usbcali.raju.model.Move;
import co.edu.usbcali.raju.model.Step;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		initProlog();
		ChessController controller=new ChessController();
		ChessGui gui=new ChessGui(controller);
		ChessBoard board=(ChessBoard)ChessBoardFactory.getInstance().getInitialBoard();
		controller.setModel(board);
		controller.addView(gui);
		board.setup(null);
        JFrame displayFrame = new JFrame("Raju Chess");
        displayFrame.getContentPane().add(gui, BorderLayout.CENTER);
        displayFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        displayFrame.pack();
        displayFrame.setVisible(true);
        try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ChessCell cell=(ChessCell)board.getCells().get(36);
		ChessPiece piece=(ChessPiece)board.getCells().get(52).getPieces().get(0);
		Step step=new Step();
		step.setPiece(piece);
		step.setTarget(cell);
		Move move=new Move();
		move.addStep(step);
        controller.doMove(move);
	}
	
	public static void initProlog(){
		String t3 = "consult('chessRules.pl')";
		Query q3 = new Query(t3);
		System.out.println( t3 + " " + (q3.hasSolution() ? "succeeded" : "failed") );
	}


}
